/*
*    Copyright (c) 2018 Shing Liu All Rights Reserved.
*
*           File : occQt.cpp
*         Author : Shing Liu(eryar@163.com)
*           Date : 2018-01-08 21:00
*        Version : OpenCASCADE7.2.0 & Qt5.7.1
*
*    Description : Qt main window for OpenCASCADE.
*/

#include "occqt.h"
#include "occView.h"
#include "model_list.h"

#include <QToolBar>
#include <QTreeView>
#include <QMessageBox>
#include <QDockWidget>
#include <QKeyEvent>

#include <gp_Circ.hxx>
#include <gp_Elips.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Lin2d.hxx>

#include <BRepLib.hxx>

#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>

#include <BRepPrimAPI_MakeBox.hxx>

#include <fan_maker.h>

occQt::occQt(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    myOccView = new OccView(this);
    //myOccView = new View(ViewHelper::InitContext(ViewHelper::InitViewer()), this);

    setCentralWidget(myOccView);

    ModelList* ms = new ModelList();
    ms->SetupContext(myOccView->getContext());
    ms->show();

    _fanMaker = new FanMaker(this, ms);

    connect(myOccView, &OccView::LeftButtonClicked, _fanMaker, &FanMaker::OnLeftButtonClicked);
    connect(this, &occQt::KeyPressed, _fanMaker, &FanMaker::OnKeyPressed);
}

occQt::~occQt()
{
}

void occQt::keyPressEvent(QKeyEvent* event)
{
    int key = event->key();
    emit KeyPressed(key);
}


void occQt::makeBox()
{
    //std::cout<<"makeBox is working"<<std::endl;
    TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(gp_Pnt(0.0,0.0,0.0),10.0,20.0,30.0).Shape();

    Handle(AIS_Shape) anAisBox=new AIS_Shape(aTopoBox);
    anAisBox->SetColor(Quantity_NOC_YELLOW);
    myOccView->getContext()->Display(anAisBox, Standard_True);
}



void occQt::on_actioneraseBox_triggered()
{
    myOccView->getContext()->EraseAll(Standard_True);
}


void occQt::on_actionreset_triggered()
{
    myOccView->reset();
}

void occQt::on_actiondefinedBox_triggered()
{
    makeBox();
}

void occQt::on_actionFan_triggered()
{
    _fanMaker->Display(myOccView->getContext());
}


